#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2018/12/5 17:20
# @Author  : lizhen
# @Site    :
# @File    : introspect.py
# @Software: PyCharm
from collections import OrderedDict

a = 1024


class Introspect:
    def __init__(self):
        pass

    def test_is_equal(self):
        b = 1024
        c = 1024
        assert b is c
        assert b is not a

    def test_str(self):
        S = 'hello world'
        assert (True if 'a' <= S[0] <= 'z' else False)

        S = '12334'
        assert S.isdigit()

        S = 'AJGWOWG'
        assert S.isalpha()

    def test_dict(self):
        a = {'name': 'xiaoming', 'age': 18, 'addr': 'shanghai'}
        for i in a.keys():
            print(i)
        for i in a.values():
            print(i)
        for i in a.items():
            print(i)
        for k, v in a.items():
            print('{0}:{1}'.format(k, v))

    def _li(self, li):
        li = li + li
        # li += li
        # li.extend(li)
        print(li)

    def test_reference(self):
        nums = [3, 5]
        self._li(nums)
        print(nums)

    def test_list_dict_set(self):
        print({i: i ** 2 for i in range(10)})
        print({i * 2 for i in range(10)})
        print([i * 2 for i in range(10)])
        print([(x, y) for x in range(10) for y in range(10, 20)])

    def test_read_big_data(self):
        with open('./MySQL.sql', 'r', encoding='utf-8', errors='ignore') as f:
            for line in f:
                print(line)

    def test_dict_sort_by_value(self):
        d = {'a': 24, 'g': 52, 'l': 12, 'k': 33}
        print(sorted(d.items(), key=lambda x: x[1]))

    def test_swap_value(self):
        a = 1
        b = 2
        a = a + b
        b = a - b
        a = a - b
        assert a == 2 and b == 1

    def test_ordered_dict(self):
        key_value = OrderedDict()
        key_value.clear()
        key_value['key'] = 'value'
        print(key_value)
        print(dir(OrderedDict))


def main():
    i = Introspect()
    # i.test_is_equal()
    # i.test_str()
    # i.test_dict()
    # i.test_reference()
    # i.test_list_dict_set()
    # i.test_read_big_data()
    # i.test_dict_sort_by_value()
    # i.test_swap_value()
    i.test_ordered_dict()


if __name__ == '__main__':
    main()
